package edu.xidian.bdilab.jrbigdata.controller.bank;

import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.service.bank.enterprieseInfoCkeck.enterprieseInfoCkeckService;
import edu.xidian.bdilab.jrbigdata.service.bank.productRelease.impl.ProductReleaseServiceImpl;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@CrossOrigin
@RestController
@Api(tags = {"productRelease-银行产品发布功能"})
public class ProductReleaseController {
    @Autowired
    edu.xidian.bdilab.jrbigdata.service.bank.productRelease.productReleaseService productReleaseService;
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productName", value = "金融产品名称"),
            @ApiImplicitParam(name = "fkBankId", value = "银行行号"),
            @ApiImplicitParam(name = "bankName", value = "银行名称"),
            @ApiImplicitParam(name = "institutionType", value = "机构类型（枚举）"),
            @ApiImplicitParam(name = "rateLowerLimit", value = "利率下限（单位%）"),
            @ApiImplicitParam(name = "rateUpperLimit", value = "利率上限（单位%）"),
            @ApiImplicitParam(name = "generality", value = "通用产品（枚举）"),
            @ApiImplicitParam(name = "internetLoanType", value = "网贷直联（枚举）"),
            @ApiImplicitParam(name = "productProperties", value = "政策性产品（枚举）"),
            @ApiImplicitParam(name = "paymentType", value = "支付方式（枚举）"),
            @ApiImplicitParam(name = "loanType", value = "贷款类别（枚举）"),
            @ApiImplicitParam(name = "loanLimit", value = "贷款额度（枚举）"),
            @ApiImplicitParam(name = "loanPeriod", value = "贷款期限（单位：月）"),
            @ApiImplicitParam(name = "guaranteeMode", value = "担保方式（枚举）"),
            @ApiImplicitParam(name = "useArea", value = "使用区域"),
            @ApiImplicitParam(name = "description", value = "说明"),
    })
    @RequestMapping(value = "bank/productRelease", method = RequestMethod.POST)
    public ResponseResult productrelease(@RequestParam String productName,
                                         @RequestParam int fkBankId,
                                         @RequestParam String bankName,
                                         @RequestParam int institutionType,
                                         @RequestParam(required = false) double rateLowerLimit,
                                         @RequestParam(required = false) double rateUpperLimit,
                                         @RequestParam int generality,
                                         @RequestParam  int internetLoanType,
                                         @RequestParam int productProperties,
                                         @RequestParam int paymentType,
                                         @RequestParam int loanType,
                                         @RequestParam int loanLimit,
                                         @RequestParam int loanPeriod,
                                         @RequestParam int guaranteeMode,
                                         @RequestParam String useArea,
                                         @RequestParam  String description)
    {
        ResponseResult responseResult= productReleaseService.productrelease(productName,
         fkBankId,
        bankName,
         institutionType,
         rateLowerLimit,
         rateUpperLimit,
         generality,
         internetLoanType,
         productProperties,
         paymentType,
         loanType,
         loanLimit,
         loanPeriod,
         guaranteeMode,
         useArea,
         description);
        return  responseResult;

    }

    @ResponseBody
    @ApiOperation("获得金融机构信息")
    @RequestMapping(value = "bank/getBankInformation", method = RequestMethod.POST)
    public ResponseResult getBankInformation(@RequestParam @ApiParam(value = "金融机构用户名") String userName,
                                             HttpSession httpSession){
        ResponseResult responseResult = productReleaseService.getBankInformation(userName);
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("查询金融产品")
    @RequestMapping(value = "bank/getFinacialProduct", method = RequestMethod.POST)
    public ResponseResult getFinacialProduct(@RequestParam(defaultValue = "1")@ApiParam(value = "页码") int pageNum,
                                             @RequestParam(defaultValue = "10")@ApiParam(value = "每页记录数") int pageSize,
                                             @RequestParam(required = false) @ApiParam(value = "金融机构名称（支持模糊查询）") String bankName,
                                             @RequestParam(required = false) @ApiParam(value = "产品名称（支持模糊查询）") String productName,
                                             @RequestParam(required = false) @ApiParam(value = "机构类型") Integer institutionType,
                                             @RequestParam(required = false) @ApiParam(value = "利率上限") Double rateUpperLimit,
                                             @RequestParam(required = false) @ApiParam(value = "利率下限") Double rateLowerLimit,
                                             @RequestParam(required = false) @ApiParam(value = "通用产品") Integer generality,
                                             @RequestParam(required = false) @ApiParam(value = "贷款期限") Integer loanPeriod,
                                             @RequestParam(required = false) @ApiParam(value = "支付方式") Integer paymentType,
                                             @RequestParam(required = false) @ApiParam(value = "贷款类别") Integer loanType,
                                             @RequestParam(required = false) @ApiParam(value = "担保方式") Integer guaranteeMode,
                                             @RequestParam(required = false) @ApiParam(value = "网贷直连") Integer internetLoanType,
                                             @RequestParam(required = false) @ApiParam(value = "政策性产品") Integer productProperties,
                                             @RequestParam(required = false) @ApiParam(value = "贷款额度") Integer loanLimit,
                                             @RequestParam(required = false) @ApiParam(value = "使用区域") String useArea,
                                             @RequestParam(required = false) @ApiParam(value = "说明") String description,
                                             HttpSession httpSession) throws Exception{
        ResponseResult responseResult = productReleaseService.getAllFinacialProduct(pageNum,pageSize,bankName,productName,institutionType,rateUpperLimit,rateLowerLimit,
                generality,loanPeriod,paymentType,loanType,guaranteeMode,internetLoanType,productProperties,loanLimit,useArea,description);
        return responseResult;
    }

    @ResponseBody
    @ApiOperation("通过银行id获取银行发布的所有产品信息")
    @RequestMapping(value = "bank/getProductByBankId", method = RequestMethod.POST)
    public ResponseResult getProductByBankId  (@RequestParam(defaultValue = "1")@ApiParam(value = "页码") int pageNum,
                                                 @RequestParam(defaultValue = "10")@ApiParam(value = "每页记录数") int pageSize,
                                                 @RequestParam int fkBankId)
    {
        ResponseResult responseResult= productReleaseService.getProductByBankId(pageNum,pageSize,fkBankId);
        return  responseResult;
    }

    @ResponseBody
    @ApiOperation("查看当前畅销的top4金融产品")
    @RequestMapping(value = "bank/getTopProduct", method = RequestMethod.POST)
    public ResponseResult getTopProduct  ()
    {
        ResponseResult responseResult= productReleaseService.getTopProduct();
        return  responseResult;
    }
}
